package com.iman.manjusri.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.iman.common.support.Page;
import com.iman.manjusri.domain.ArticleBean;
import com.iman.manjusri.domain.CourseInfoBean;
import com.iman.manjusri.domain.CourseTypeBean;
import com.iman.manjusri.domain.SessionBean;
import com.iman.manjusri.domain.User;
import com.iman.manjusri.mappers.models.DrmCourse;
import com.iman.manjusri.service.ArticlesService;
import com.iman.manjusri.service.CourseInfoService;
import com.iman.manjusri.service.CourseTypeService;
import com.iman.manjusri.service.GroupService;
import com.iman.manjusri.service.HomeHyService;
import com.iman.manjusri.vo.CaseVo;
import com.iman.manjusri.vo.GroupInfoVo;
import com.iman.manjusri.vo.HomeVo;


@Controller
@RequestMapping(value = "/*")
public class IndexController extends BaseController {
	
	  @Autowired
	  CourseTypeService  courseTypeService;
	  
	  @Autowired
	  ArticlesService articleService;
	  @Autowired
	  CourseInfoService courseInfoService;
	  @Autowired
	  HomeHyService homeHyService;
	  @Autowired
	  GroupService groupService;
	  
	  @RequestMapping(value = "//")
	  public ModelAndView homePage( HttpServletRequest request){
		  Map<String,Object> result = new  HashMap<String,Object>();
		  ModelAndView view = null;
		  
		  //获取左侧课程信息
		  //从drm_course_type表中取数据
		  List<CourseTypeBean> courseTypeBeanList = courseTypeService.getCourseTypeBeanList();
		  //获取通知信息
		  //从drm_articles表中取数据
		  //获取3条公开课
		  Map<String,Object> gongkaikeMap = new HashMap<String,Object>();
		  gongkaikeMap.put("courseClass", "1");
		  gongkaikeMap.put("offset", 0);
		  gongkaikeMap.put("limit", 3);
		  List<CourseInfoBean> gongkaikeCourseList = courseInfoService.getCourseInfoList(gongkaikeMap);
		  
		  
		  //7条通知
		  Map<String,Object> tongzhiMap = new HashMap<String,Object>();
		  tongzhiMap.put("article_tp", 1);
		  tongzhiMap.put("offset", 0);
		  tongzhiMap.put("limit", 7);
		  List<ArticleBean> tongzhiArticleList = articleService.getArticleList(tongzhiMap);
		  //1= 通知公告  2= 学院动态       3= 行业动态      4= 考试指南     5=备考指南    6=考试动态    7=报考指南     8=制定用书   9=证书与就业   10=活动   11=考点总结    12= 同步练习   13=历年真题    14= 论文辅导
		  //3条学院动态 2
		  Map<String,Object> xueyuandongtaiMap = new HashMap<String,Object>();
		  xueyuandongtaiMap.put("article_tp", 2);
		  xueyuandongtaiMap.put("offset", 0);
		  xueyuandongtaiMap.put("limit", 3);
		  List<ArticleBean> xueyuandongtaiArticleList = articleService.getArticleList(xueyuandongtaiMap);
		  //3条行业动态  3
		  Map<String,Object> hangyedongtaiMap = new HashMap<String,Object>();
		  hangyedongtaiMap.put("article_tp", 3);
		  hangyedongtaiMap.put("offset", 0);
		  hangyedongtaiMap.put("limit", 3);
		  List<ArticleBean> hangyedongtaiArticleList = articleService.getArticleList(hangyedongtaiMap);
		  //5条考试指南 4
		  Map<String,Object> kaoshizhinanMap = new HashMap<String,Object>();
		  kaoshizhinanMap.put("article_tp", 4);
		  kaoshizhinanMap.put("offset", 0);
		  kaoshizhinanMap.put("limit", 7);
		  List<ArticleBean> kaoshizhinanArticleList = articleService.getArticleList(kaoshizhinanMap);
		  
		  //5条考试动态6
		  Map<String,Object> kaoshidongtaiMap = new HashMap<String,Object>();
		  kaoshidongtaiMap.put("article_tp", 6);
		  kaoshidongtaiMap.put("offset", 0);
		  kaoshidongtaiMap.put("limit", 5);
		  List<ArticleBean> kaoshidongtaiArticleList = articleService.getArticleList(kaoshidongtaiMap);
		  
		  //5条报考指南 7
		  Map<String,Object> baokaozhinanMap = new HashMap<String,Object>();
		  baokaozhinanMap.put("article_tp", 7);
		  baokaozhinanMap.put("offset", 0);
		  baokaozhinanMap.put("limit", 5);
		  List<ArticleBean> baokaozhinanArticleList = articleService.getArticleList(baokaozhinanMap);
		  
		  //5条指定用书 8
		  Map<String,Object> zhidingyongshuMap = new HashMap<String,Object>();
		  zhidingyongshuMap.put("article_tp", 8);
		  zhidingyongshuMap.put("offset", 0);
		  zhidingyongshuMap.put("limit", 5);
		  List<ArticleBean> zhidingyongshuArticleList = articleService.getArticleList(zhidingyongshuMap);
		  //5条证书与就业 9
		  Map<String,Object> zhengshuyujiuyeMap = new HashMap<String,Object>();
		  zhengshuyujiuyeMap.put("article_tp", 9);
		  zhengshuyujiuyeMap.put("offset", 0);
		  zhengshuyujiuyeMap.put("limit", 5);
		  List<ArticleBean> zhengshuyujiuyeArticleList = articleService.getArticleList(zhengshuyujiuyeMap);
		  //5条考点总结 11
		  Map<String,Object> kaodianzongjieMap = new HashMap<String,Object>();
		  kaodianzongjieMap.put("article_tp", 11);
		  kaodianzongjieMap.put("offset", 0);
		  kaodianzongjieMap.put("limit", 5);
		  List<ArticleBean> kaodianzongjieArticleList = articleService.getArticleList(kaodianzongjieMap);
		  //5条同步练习 12
		  Map<String,Object> tongbulianxiMap = new HashMap<String,Object>();
		  tongbulianxiMap.put("article_tp", 12);
		  tongbulianxiMap.put("offset", 0);
		  tongbulianxiMap.put("limit", 5);
		  List<ArticleBean> tongbulianxiArticleList = articleService.getArticleList(tongbulianxiMap);
		  //5条历年真题 13
		  Map<String,Object> linianzhentiMap = new HashMap<String,Object>();
		  linianzhentiMap.put("article_tp", 13);
		  linianzhentiMap.put("offset", 0);
		  linianzhentiMap.put("limit", 5);
		  List<ArticleBean> linianzhentiArticleList = articleService.getArticleList(linianzhentiMap);
		  //5条论文辅导  14
		  Map<String,Object> lunwenfudaoMap = new HashMap<String,Object>();
		  lunwenfudaoMap.put("article_tp", 14);
		  lunwenfudaoMap.put("offset", 0);
		  lunwenfudaoMap.put("limit", 5);
		  List<ArticleBean> lunwenfudaoArticleList = articleService.getArticleList(lunwenfudaoMap);
		  
		  //婚姻家庭
		  Map<String,Object> marrageCaseMap = new HashMap<String,Object>();
		  marrageCaseMap.put("articleTp", 1111);
		  marrageCaseMap.put("offset", 0);
		  marrageCaseMap.put("limit", 5);
		  
		  List<CaseVo> marrageCaseList = articleService.listIndexCase(marrageCaseMap);
		  if(marrageCaseList.size() > 0 ){
			  result.put("marrageCase", marrageCaseList.get(0));
		  }
		  
		  //亲子关系
		  Map<String,Object> childCaseMap = new HashMap<String,Object>();
		  childCaseMap.put("articleTp", 1112);
		  childCaseMap.put("offset", 0);
		  childCaseMap.put("limit", 5);
		  List<CaseVo> childCaseList = articleService.listIndexCase(childCaseMap);
		  if(childCaseList.size() > 0 ){
			  result.put("childCase", childCaseList.get(0));
		  }
		  
		  //职业减压
		  Map<String,Object> jobCaseMap = new HashMap<String,Object>();
		  jobCaseMap.put("articleTp", 1113);
		  jobCaseMap.put("offset", 0);
		  jobCaseMap.put("limit", 5);
		  List<CaseVo> jobCaseList = articleService.listIndexCase(jobCaseMap);
		  if(jobCaseList.size() > 0 ){
			  result.put("jobCase", jobCaseList.get(0));
		  }
		  
		  //教师
		  Page<HomeVo> teacherHomePage = homeHyService.getHome(2, 3, 1);
		  List<HomeVo> teacherHomeList = teacherHomePage.getData();
		  //学员
		  Page<HomeVo> studentHomePage = homeHyService.getHome(4, 3, 1);
		  List<HomeVo> studentHomeList = studentHomePage.getData();
		  //群组
		  List<GroupInfoVo> groupHomeList = groupService.getThreeGroupInfo();
		  
		  
		  
		  result.put("courseType", courseTypeBeanList);
		  result.put("courseNotify", null);
		  result.put("gongkaikeCourseList", gongkaikeCourseList);
		  result.put("tongzhiArticleList", tongzhiArticleList);
		  
		  result.put("xueyuandongtaiArticleList", xueyuandongtaiArticleList);
		  result.put("hangyedongtaiArticleList", hangyedongtaiArticleList);
		  result.put("kaoshizhinanArticleList", kaoshizhinanArticleList);
		  result.put("kaoshidongtaiArticleList", kaoshidongtaiArticleList);
		  result.put("baokaozhinanArticleList", baokaozhinanArticleList);
		  result.put("zhidingyongshuArticleList", zhidingyongshuArticleList);
		  result.put("zhengshuyujiuyeArticleList", zhengshuyujiuyeArticleList);
		  result.put("kaodianzongjieArticleList", kaodianzongjieArticleList);
		  result.put("tongbulianxiArticleList", tongbulianxiArticleList);
		  result.put("linianzhentiArticleList", linianzhentiArticleList);
		  result.put("lunwenfudaoArticleList", lunwenfudaoArticleList);
		  result.put("teacherHomeList", teacherHomeList);
		  result.put("studentHomeList", studentHomeList);
		  result.put("groupHomeList", groupHomeList);
		  result.put("marrageCaseList", marrageCaseList);
		  result.put("childCaseList", childCaseList);
		  result.put("jobCaseList", jobCaseList);
		  
		  
		  view = new ModelAndView("index",result);
		  
		  
		  
		  //重新刷新首页如果登陆了 ，就显示内容
		  
		  SessionBean sbean =  super.getSession(request);
		 
		  if(sbean!=null && sbean.getUser()!=null){
			  User user =  sbean.getUser();
			  view.addObject("login", true);
				
			    view.addObject("imgKey", user.getUser_himg());
				view.addObject("uName", user.getLoginName());
				
				// userType = 5;  用户类型 类型1,系统管理员；2，管理员；3，教师；4，代理商；5，注册用户；
				if(user.getUserType()==1)  {
					
				}else if(user.getUserType()==2)  {
					
				}else if(user.getUserType()==3)  {
					view.addObject("forward", super.forward_teacher);
				}else if(user.getUserType()==4)  {
					view.addObject("forward", super.forward_agent);
				}else if(user.getUserType()==5)  {
					view.addObject("forward", super.forward_student);
				}
		  }
			
		  
		  //资源 图片js css
		  putResourceSrc(view);	
		  
		  return view;
	  }
	  /*
	  	@RequestMapping(value = "//courseIndex/getDiv")  
	    @ResponseBody  
	    public Object test(HttpSession session){  
	  		String html = "<div id='coursediv1' name='coursediv' class='web_divmidbr'>"+
					"<div class='web_divmidbr01'> <a href='drm_kczx_son.htm'>"+
					"<div class='web_divmidbr02'> <img src='${imgpath}/images/courcent01.jpg'/> </div>"+
					"</a> <a href='drm_kczx_son.htm'>"+
					"<div class='web_divmidbr03'> 专注心理咨询11年1<br/>"+
					"	通过率全国领先 </div>"+
					"</a> </div>"+
					"<div class='web_divmidbr01'> <a href='drm_kczx_son.htm'>"+
					"<div class='web_divmidbr02'> <img src='${imgpath}/images/courcent01.jpg'/> </div>"+
					"</a> <a href='drm_kczx_son.htm'>"+
					"<div class='web_divmidbr03'> 专注心理咨询11年1<br/>"+
					"	通过率全国领先 </div>"+
					"</a> </div>"+
					"<div class='web_divmidbr01'> <a href='drm_kczx_son.htm'>"+
					"<div class='web_divmidbr02'> <img src='${imgpath}/images/courcent01.jpg'/> </div>"+
					"</a> <a href='drm_kczx_son.htm'>"+
					"<div class='web_divmidbr03'> 专注心理咨询11年1<br/>"+
					"	通过率全国领先 </div>"+
					"</a> </div>"+
					"<a href='course_center.htm'>"+
					"<div class='web_divmidbrmore'> 更<br/>"+
					"多 </div>"+
					"</a> </div>";
	        return html;  
	    }  
	  */
	  
	 
	  @RequestMapping(value = "//courseIndex/getDiv")
	  public ModelAndView couse( HttpServletRequest request){
		  Map<String,Object> result = new  HashMap<String,Object>();
		  ModelAndView view = null;
		  String courseTp = request.getParameter("typeName");
		  Map<String,Object> searchMap = new HashMap<String,Object>();
		  searchMap.put("courseTp", courseTp);
		  List<DrmCourse> drmCourse = courseInfoService.getCourseInfoByType(searchMap);
		  result.put("drmCourseList", drmCourse);
		  view = new ModelAndView("kcjs",result);
		  putResourceSrc(view);	
		  return view;
	  }
}
